package com.ophiux.cs.application.user.impl.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.application.core.Throws.ParamException;
import com.ophiux.cs.application.user.dto.getUserByUseridRequest;
import com.ophiux.cs.application.user.dto.getUserByUseridResponse;
import com.ophiux.cs.domain.user.domainservice.UserDomainService;
import com.ophiux.cs.domain.user.model.entity.User;
import com.ophiux.cs.domain.user.repositories.IUserRepository;
import com.ophiux.utils.common.ShiftUtils;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class getUserByUseridService {
	
	@Autowired
	IUserRepository iUserRepository;
	@Autowired
	UserDomainService userDomainService;

	public Result<getUserByUseridResponse> getUserByUserid(getUserByUseridRequest dto) {
		Result<getUserByUseridResponse> result = new Result<getUserByUseridResponse>();
		getUserByUseridResponse res = new getUserByUseridResponse();
		try {
			try {
				//验证参数是否允许为空
				dto.paramVer();
			} catch (ParamException e) {
				return Result.fail(ResultEnum.requestParamFail.getCode(), e.getMessage()); 
			}
			
			String userId = dto.getUSER_ID();
			User user = iUserRepository.getUserByUserId(userId);
			
			res = (getUserByUseridResponse) ShiftUtils.objToNewObj(user, getUserByUseridResponse.class);
			result = Result.success(res);
			
		} catch (Exception e) {
			log.info("getUserByUserid接口异常：",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
		return result;
	}
	
}
